/**
 * 
 */
package t4j.arrays;


import java.util.Arrays;

import t4j.net.mindview.util.ConvertTo;
import t4j.net.mindview.util.Generated;
import t4j.net.mindview.util.Generator;
import t4j.net.mindview.util.RandomGenerator;


public class ArraySearching {
	public static void main(String[] args) {
		Generator<Integer> gen = new RandomGenerator.Integer(1000);
		
		int[] a = ConvertTo.primitive(Generated.array(new Integer[25], gen));
		
		Arrays.sort(a);
		
		System.out.println("Sorted array: " + Arrays.toString(a));
		
		while(true){
			int r = gen.next();
			
			int location = Arrays.binarySearch(a, r);
			
			if(location >= 0){
				System.out.println("Location of " + r + " is " + location + ", a[" + location + 
						"] = " + a[location]);
				
				break;
			}
		}
	}
}
